package com.wunong.smart.collection.converter;

import com.wunong.smart.collection.client.dto.CollectionDTO;
import com.wunong.smart.collection.domain.model.CollectionDomain;
import com.wunong.smart.domain.platform.common.ICode;
import org.apache.commons.collections.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author create by zealot.zt
 */
public final class CollectionModelConverter {

    public static List<CollectionDTO> toDto(List<CollectionDomain> domains) {
        if (CollectionUtils.isEmpty(domains)) {
            return null;
        }

        return domains.stream().map(CollectionModelConverter::toDto).collect(Collectors.toList());
    }

    public static CollectionDTO toDto(CollectionDomain domain) {
        if (domain == null) {
            return null;
        }

        CollectionDTO dto = CollectionDTO.of();

        dto.init(domain);

        dto.setSource(domain.getSource());
        dto.setUser(domain.getUser());
        dto.setCollectType(domain.getCollectType());
        dto.setStatus(ICode.withCode(domain.getStatusEnum()));

        return dto;
    }

}
